/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Navigator,
    ListView,
    TouchableOpacity
} from 'react-native';

var MLTableCell = require('../MLTableCell/MLTableCell');
var NewFriends = require('../新的朋友/MLNewFriends')
var MLNavigatorBar = require('../MLNavigatorBar/MLNavigatorBar');
var Main = React.createClass({
    getInitialState() {

        var tableData = [];

        //判断用户类别
        tableData.push('新的朋友')
        tableData.push('我的医生')
        tableData.push('我的好友')
        tableData.push('最近联系')

        //ListView设置
        var ds = new ListView.DataSource({rowHasChanged:(r1, r2) => r1 !== r2});
        return {
            //ListView设置
            dataSource: ds.cloneWithRows(tableData)
        }
    },
    render(){
        return(
            <View style={styles.container}>
                <MLNavigatorBar title={'消息'} rightBtnImage = {require('../../images/newAdd1.png')} isBack={true}
                                backFunc={() => {
                    this.props.navigator.pop()
                }}/>
                <ListView
                    dataSource={this.state.dataSource}//数据源
                    renderRow={this.renderRow}
                />
            </View>
        )
    },
    //返回具体的cell
    renderRow(rowData){
        if (rowData == "新的朋友"){
            return(
                <TouchableOpacity onPress={()=>{
                    // 页面的切换
                    this.props.navigator.push({
                        component: NewFriends, // 具体路由的版块
                    });
                }}>
                    <MLTableCell title={rowData} iconTitl={require('../../images/friend_famous.png')}/>
                </TouchableOpacity>
            )
        }else if (rowData == "我的医生"){
            return(
                <TouchableOpacity onPress={()=>{

                }}>
                    <MLTableCell title={rowData} iconTitl={require('../../images/医生.png')}/>
                </TouchableOpacity>
            )
        }else if (rowData == "我的好友"){
            return(
                <TouchableOpacity onPress={()=>{

                }}>
                    <MLTableCell title={rowData} iconTitl={require('../../images/我的.png')}/>
                </TouchableOpacity>
            )
        }else {
            return(
                <TouchableOpacity onPress={()=>{

                }}>
                    <MLTableCell title={rowData} iconTitl={require('../../images/friend_favor.png')}/>
                </TouchableOpacity>
            )
        }
    },
})

const styles = StyleSheet.create({
    container: {
        flex: 1,
    },
});

//输出
module.exports = Main;